/**
 *  * Created by wz on 2017/9/26
 *  * <p/>
 *  * Copyright (c) 2015-2015
 *  * Apache License
 *  * Version 2.0, January 2004
 *  * http://www.apache.org/licenses/
 *  
 */
package com.huirui.controller;

import com.huirui.entity.Identity;
import com.huirui.entity.User;
import com.huirui.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping(value = "user/insert/{username}/{password}/{identity}",method = RequestMethod.GET)
    public String registerUser(@PathVariable("username")String username,
                               @PathVariable("password")String password,
                               @PathVariable("identity") Integer identityid){

        User user = new User(username,password,new Identity(identityid,null));

        userService.insertUser(user);
        
        return "user insert success";
    }

    @RequestMapping(value = "user/queryByIdentity/{identityId}")
    public List<User> queryByIdentity(@PathVariable("identityId")Integer identityId){

        return userService.queryByIdentity(new Identity(identityId,null));

    }

}
